package com.rockcent.mall.lib.repository;

import com.rockcent.common.domain.enumclass.Whether;
import com.rockcent.mall.lib.domain.Product;
import com.rockcent.mall.lib.domain.enumclass.ProductStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * Created by DK on 16/9/18.
 * 产品管理
 */
@Repository
public interface MerchantProductRepository extends JpaRepository<Product, Long>, JpaSpecificationExecutor, MerchantProductRepositoryCustom {

    List<Product> findByMarketIdAndIsDelete(Long marketId,Whether isDelete);

    Product findByIdAndMerchantId(Long id, Long merchantId);

    Product findByIdAndIsDelete(Long id, Whether isDelete);

    List<Product> findByIdInAndStatus(List<Long> ids,ProductStatus status);

    List<Product> findByIdIn(List<Long> ids);
    List<Product> findByIdInAndMarketIdIsNull(List<Long> ids);

    List<Product> findByMallIdAndMerchantIdAndIsDelete(Long mallId,Long merchantId,Whether isDelete);


    List<Product> findByMallIdAndStatusAndMarketIdIsNullAndDateSellingBeforeOrderByLastUpdatedDesc(Long mallId, ProductStatus status, Date dateSelling);


    List<Product> findByMerchantIdAndIdIn(Long id, List<Long> collocationProductIds);

    List<Product> findByMerchantIdAndIdInAndStatus(Long merchantId, List<Long> productIds, ProductStatus status);

    Product findByIdAndMerchantIdAndMallId(Long newProductId, Long merchantId, Long mallId);


    Product findByIdAndMerchantIdAndIsDeleteAndStatus(Long productId, Long id, Whether isDelete, ProductStatus soldout);

    List<Product> findByIdInAndMallIdAndIsDelete(List<Long> ids, Long mallId, Whether isDelete);

    Product findByIdAndIsDeleteAndStatus(Long productId, Whether no, ProductStatus soldout);

    List<Product> findByMarketId(Long productId);

    Product findByMarketIdAndMerchantIdAndMallIdAndIsDeleteAndStatus(Long productId, Long merchantId, Long mallId, Whether isDelete, ProductStatus selling);


    int countByMallIdAndIsDeleteAndStatusInAndMarketIdIsNull(Long mallId, Whether isDelete, List<ProductStatus> statusList);

    List<Product> findByMarketIdAndIsDeleteAndStatusIn(Long id, Whether isDelete, List<ProductStatus> statusList);

    List<Product> findByMerchantIdAndMarketIdAndStatusIn(Long marketDistributorMerchantId, Long marketMerchantProductSalesProductId, List<ProductStatus> statusList);

    Product findByMarketIdAndMerchantIdAndIsDelete(Long productId, Long merchantId, Whether isDelete);

    Product findByMarketIdAndMerchantId(Long productId, Long merchantId);

    List<Product> findByIdInAndMallId(List<Long> productIds,Long mallId);

    Product findByIdAndMallId(Long id, Long mallId);

    List<Product> findByMallIdAndMerchantIdInAndIsDelete(Long mallId, List<Long> merchantIds, Whether no);

    List<Product> findByMallIdAndIsDelete(Long mallId, Whether no);

    List<Product> findByMallIdAndIsDeleteOrderByIdDesc(Long mallId, Whether no);

}
